package in.ac.dei.edrp.cms.controller.studentregistration;

import java.util.List;

import in.ac.dei.edrp.cms.common.utility.MyException;
import in.ac.dei.edrp.cms.dao.studentregistration.LoginConnectDao;
import in.ac.dei.edrp.cms.domain.LoginInfoGetter;
import in.ac.dei.edrp.cms.domain.login.Login;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


public class StudentLoginController extends MultiActionController {
    private LoginConnectDao LoginConnect;

    /**
     * Method to initialize controller
     * @param loginConnect
     */
    public void setLoginConnectDao(LoginConnectDao loginConnect) {
        this.LoginConnect = loginConnect;
    }

    /**
     * Method for checking valid login and  getting student's id
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView getStudentLoginInfo(HttpServletRequest request,
        HttpServletResponse response) throws Exception {
        LoginInfoGetter input = new LoginInfoGetter();
        input.setUserName(request.getParameter("user_name"));
        input.setPassword(request.getParameter("password"));
        LoginInfoGetter result=null;
try{
        result = LoginConnect.getStudentLoginInfo(input);
        
        HttpSession session = request.getSession(true);
		session.setAttribute("userName", input.getUserName());
			
}catch (MyException e) {
	return new ModelAndView("RegistrationForm/RegisterStudent", "result",
            e.getMessage());
} 
        return new ModelAndView("RegistrationForm/LoginInfo", "result", result);
    }
}
